package org.jackysoft.entity;

import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jackysoft.entity.Department;

import com.google.common.collect.Lists;

@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Product extends AbstractProduct {

	/**
	 * 
	 */
	private static final long serialVersionUID = -116341335161418701L;
	// 可能生产厂家
	private Collection<Department> providers = Lists.newArrayList();    
	private Collection<Technics> technics = Lists.newArrayList();
	
	public Product() {
	}

	public Product(String code) {
		this.code = code;
	}

	public Product(String code, String name) {
		
		this.name = name;
		this.code = code;
	}

	public Product(String code, String name, Double price,
			String priceUnit) {
		super(code, name, price, priceUnit);
	}

	public Product(String code, String name,
			Collection<Department> providers) {		
		this.name = name;
		this.code = code;
		this.providers = providers;
	}

	@ManyToMany(targetEntity = Department.class)
	@JoinTable(name = "product_departments", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "department_id"))
	@JSON(serialize = false)
	public Collection<Department> getProviders() {
		return providers;
	}

	public void setProviders(Collection<Department> providers) {
		this.providers = providers;
	}

	@Transient@JSON(serialize = false)
	public Collection<Technics> getTechnics() {
		return technics;
	}

	public void setTechnics(Collection<Technics> technics) {
		this.technics = technics;
	}

}